package com.des1gn.servicea.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.des1gn.servicea.blockhandle.TestBlockHandle;
import com.des1gn.servicea.feign.ServicebFeign;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TestController
 * @Description TODO
 * @Author Des1gn
 * @Date 2021/9/29 13:54
 * @Version 1.0
 **/
@RestController
public class TestController {

    @Autowired
    ServicebFeign servicebFeign;

    int i = 0;

    @GetMapping("test")
    @GlobalTransactional()
    @SentinelResource(value = "test",
            blockHandlerClass = {TestBlockHandle.class},
            blockHandler = "exceptionHandle",
            fallbackClass={TestBlockHandle.class},
            fallback = "follbackHandle")
    public String test(String ack){
        i++;
        if (i > 50) {
            System.out.println(1 / 0);
        }
        return servicebFeign.test(ack);
    }

}
